package sql2005;

import java.sql.*;

public class ParameterUpdate {
	public static void main(String[] args) {
		try {
			// load driver
//			 Class.forName("net.sourceforge.jtds.jdbc.Driver");
			 Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			System.out.println("driver da duoc load ");
			// tao ket noi den CSDL
//			 Connection connection = DriverManager.getConnection(
//			 "jdbc:jtds:sqlserver://localhost:1433/test", "sa",
//			 "sa");
			Connection connection = DriverManager
					.getConnection("jdbc:sqlserver://localhost:1433;databaseName=test;user=sa;password=1234567");
			System.out.println("Da ket noi duoc voi CSDL");
			// tao cau truy van
			String sql = "INSERT INTO SinhVien VALUES(?, ?)";
			// thuc hien cau truy van
			PreparedStatement state = connection.prepareStatement(sql);
			
			state.setInt(1, 123);
			state.setString(2, "Nguyen Cao Cuong");
			
			int rs = state.executeUpdate();
			
			System.out.println("Update = " + rs);
		
		} catch (ClassNotFoundException ex) {
			ex.printStackTrace();
		} catch (SQLException ex) {
			ex.printStackTrace();
		}

	}
}
